Python使用常见错误汇总

您所在的位置:网站首页 无法安装pandas 库 Python使用常见错误汇总

Python使用常见错误汇总

2024-07-03 11:05| 来源: 网络整理| 查看: 265

一、安装pandas超时错误处理方法

需要操作csv文件,安装pandas时

输入

pip install pandas

没有想到出错了,提示read timed out。

搜资料提示需要处理默认的超时时间,修改命令:

pip --default-time=100 install pandas

安装完成。

又搜了下,除了设置default-time参数,也可以切换国内的镜像源。

修改镜像源有两种:

(1)临时修改

  使用pip的时候在后面加上-i参数,指定pip源 

pip install -i https://pypi.douban.com/simple django pip install crypto -i https://pypi.tuna.tsinghua.edu.cn/simple/

(2)永久修改

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

pip.ini的内容

[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple

如果是win10 地址栏输入 %APPDATA%,如果没有pip文件夹,就手动创建pip及下面的 pip.ini

附上国内常用的镜像源

阿里云:https://mirrors.aliyun.com/pypi/simple/ 中国科技大学:https://pypi.mirrors.ustc.edu.cn/simple/ 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/ 豆瓣:http://pypi.douban.com/simple/ 二、ModuleNotFoundError: No module named cryptography.fernet

安装fernet后,引用cryptography

from cryptography.fernet import Fernet

报错:ModuleNotFoundError: No module named cryptography.fernet

解决办法:安装cryptography

-----------------------------------------

三、Unicode-objects must be encoded before hashing 错误解决办法 #报错代码 hashlib.sha256(username_trial).hexdigest() #修改为 hashlib.sha256(username_trial.encode("utf-8")).hexdigest()

原因:hashlib这个库只接收byte数组数据,所以,需要将string变量转成byte数组即可

四、pip 最常用命令

1.显示版本和路径

pip --version

2.获取帮助

pip --help

3.升级 pip

pip install -U pip

如果这个升级命令出现问题 ,可以使用以下命令:

sudo easy_install --upgrade pip

4.安装指定包

pip install SomePackage # 最新版本 pip install SomePackage==1.0.4 # 指定版本 pip install 'SomePackage>=1.0.4' # 最小版本

比如我要安装 Django。用以下的一条命令就可以,方便快捷。

pip install Django==1.7

5.升级包

pip install --upgrade SomePackage

升级指定的包,通过使用==, >=, , < 来指定一个版本号。

6.卸载包

pip uninstall SomePackage

7.搜索包

pip search SomePackage

8.显示安装包信息

pip show

9.查看指定包的详细信息

pip show -f SomePackage

10.列出已安装的包

pip list

11.查看可升级的包

pip list -o



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3